import { pollPay } from "./utils/pollPay.js";
import { log } from "./utils/util.js";
import { cookieJar, Cookie } from "./utils/cookie.js";
import config from "./config.js";

const url = "https://mclient.alipay.com";

const configCookies = config.cookie.split(";").map(Cookie.parse);

const cookieStr = await cookieJar.getCookieString(url);
if (cookieStr) {
  log(`使用缓存cookie`);
} else {
  log(`cookie无缓存，使用config中cookie`);
  for (const cookie of configCookies) {
    await cookieJar.setCookie(cookie, url);
  }
}

log("cookie: ", await cookieJar.getCookieString(url));

pollPay();
